layui.use(['form', 'layer', 'fsoft'], function () {
	var form = layui.form,
		layer = layui.layer
		, fsoft = layui.fsoft;
	var rwid = $('#id').val();
	var orgTrees;
	//
	$.post(layui.cache['contentPath'] + "/sys-area/findList", {}, function (data) {
		data = eval('(' + data + ')');
		if (data.code == "0") {
			orgTrees = xmSelect.render({
				el: '#xm-select-Area',
				initValue: [$('#parentId').val()],
				prop: { name: 'name', value: 'id' },
				theme: { color: '#0081ff' },
				data: data.data,
				paging: true,
				pageSize: 5,
				radio: true,
				clickClose: true,
				size: 'medium',
				name: "parentId",
				on: function (data) {
					var arr = data.arr;
					if (data.isAdd) {
						$('#parentId').val(arr[0].id);
					} else {
						$('#parentId').val("");
					}
				}
			});
		}
	});

	// 监听提交
	form.on('submit(save)', function (data) {
		var submitUrl = layui.cache['contentPath'] + '/sys-area/save';
		if (rwid != undefined && rwid != "") {
			submitUrl = layui.cache['contentPath'] + '/sys-area/modify';
		}
		fsoft.put(submitUrl, data.field, function (rs) {
			if (rs.code == 0) {
				fsoft.successMsg((rwid != undefined && rwid != "") ? "新增成功" : "编辑成功");
				xadmin.close();
				xadmin.father_reload();
			} else {
				fsoft.errorMsg(rs.msg);
			}
		});
		return false;
	});
});